package com.capsulode.jdbc;

/**
 * SqlUpdate.
 */
public class SqlUpdate extends DefaultSqlBuilder {
    private boolean clean = true;

    public SqlUpdate(CharSequence tableName) {
        super("update ");
        super.concat(tableName);
    }

    public SqlUpdate set(CharSequence column, Object value) {
        if (clean) {
            super.concat(" set ");
            clean = false;
        } else {
            super.concat(", ");
        }
        concat(column);
        if (value instanceof SqlFunction) {
            SqlFunction func = (SqlFunction) value;
            concat(" = ").concat(func.getTemplate(), func.getParams());
            return this;
        }
        concat(" = ?", value);
        return this;
    }


    //<editor-fold desc="Override Methods">
    @Override
    public DefaultSqlBuilder append(String piece, Object... params) {
        return super.append(piece, params);
    }

    @Override
    public DefaultSqlBuilder prepend(String piece, Object... params) {
        return super.prepend(piece, params);
    }

    @Override
    public DefaultSqlBuilder where() {
        return super.where();
    }

    @Override
    public DefaultSqlBuilder where(CharSequence condition, Object... params) {
        return super.where(condition, params);
    }
    //</editor-fold>
}
